package cn.doitedu.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.tool.LoadIncrementalHFiles;

import java.io.IOException;

public class HFileBulkLoader {

    public static void main(String[] args) throws IOException {

        Configuration conf = HBaseConfiguration.create();
        Connection conn = ConnectionFactory.createConnection(conf);
        TableName tableName = TableName.valueOf("doit:students");

        Admin admin = conn.getAdmin();
        Table table = conn.getTable(tableName);
        RegionLocator locator = conn.getRegionLocator(tableName);


        LoadIncrementalHFiles loadIncrementalHFiles = new LoadIncrementalHFiles(conf);
        long start = System.currentTimeMillis();
        loadIncrementalHFiles.doBulkLoad(new Path("hdfs://doit01:8020/doit_students_hfiles/"), admin, table, locator);
        long end = System.currentTimeMillis();
        System.out.println("导入总耗时(ms)： "  + (end-start));

        table.close();
        admin.close();
        conn.close();
    }
}